package org.paradise.dms.dao.impl;

import org.apache.log4j.Logger;
import org.paradise.dms.pojo.SystemUser;
import org.springframework.stereotype.Service;

import com.dheaven.framework.dao.BaseHibernateDao;
import com.dheaven.framework.dao.DaoException;

@SuppressWarnings("unchecked")
@Service
public class ChangePasswordDAOImpl extends BaseHibernateDao{
	@SuppressWarnings("unused")
	private static Logger log = Logger.getLogger(ChangePasswordDAOImpl.class);
	
	/**
	 * 
	 * Description: 修改密码
	 * @Version1.0 Oct 25, 2009 6:02:23 PM 郑旭（zhengxu2006@gmail.com）创建
	 * @param oldPwd
	 * @param newPwd
	 * @param userid
	 * @return
	 */
	public String changePwd(String oldPwd,String newPwd,int userid){
		try {
			SystemUser user = (SystemUser)this.find("from SystemUser where systemuserid = "+ userid).get(0);
			if(!oldPwd.equals(user.getSystemuserpassword())){
				return "旧密码错误!";
			}else{
				user.setSystemuserpassword(newPwd);
				this.update(user);
				log.info("DMS_info：" + "id为"+userid+"的用户修改了密码");
				return "修改成功";
			}
		} catch (DaoException e) {
			e.printStackTrace();
			return "系统忙,请稍候再试";
		}
	}
}